import java.io.*;
import java.util.Arrays;
import java.util.Scanner;


public class Rcc2013Q1_B {
	//static InputStream in = System.in;
	static InputStream in;
	static BufferedWriter out;
	static Scanner scanner;
	
	static {
		try {
			in = System.in;
			//in = new FileInputStream("rcc/2013/input.txt");
			scanner = new Scanner(in);
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			//out = new BufferedWriter(new FileWriter("rcc/2013/output.txt"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static int bsearch(int[] a, int x) {
		return bsearch(a, x, 0 , a.length - 1);
	}
	
	private static int bsearch(int[] a, int x, int start, int finish) {
		while (start < finish) {
			int m = (start + finish) >> 1;
			if (x > a[m]) start = m+1;
			else finish = m;
		}
		if (x == a[start]) return start;
		else if (x < a[start]) return -start - 1;
		else return -start - 2;
	}
	
	public static void main(String[] args) throws Exception {
		int t = scanner.nextInt();
		for (int tt = 0; tt<t; tt++) {
			int n = scanner.nextInt();
			int a[] = new int[n];
			for (int i=0; i<n; i++) a[i] = scanner.nextInt();
			Arrays.sort(a);
			
			int ngroups = 0; 
			int prev = -1;
			for (int i=0; i<n; i++) {
				if (a[i] != prev) {
					prev = a[i];
					ngroups ++;
				}				
			}
			
			int [] elPerGroup = new int[ngroups];
		    int [] len = new int[ngroups];
		    prev = -1;
		    int ngroup = -1;
		    for (int i=0; i<n; i++) {
				if (a[i] != prev) {
					prev = a[i];
					len[++ngroup] = a[i];
					elPerGroup[ngroup] = 1;
				}
				else {
					elPerGroup[ngroup] ++;
				}
		    }
		    
		    long res = 0;
		    
		    int []sum = new int[ngroups];
		    sum[0] = elPerGroup[0];
		    for (int i=1; i<ngroups; i++) sum[i] = sum[i-1]+elPerGroup[i];
		    
		    for (int i=0; i<ngroups; i++) {
		    	if (elPerGroup[i] > 1) {
		    		int l = len[i]*2;
		    		long x = ((elPerGroup[i]-1)*(long)elPerGroup[i])/2;
		    		for (int j=0; j<ngroups; j++) {
		    			if (i != j) {
		    				int k = bsearch(len, len[j]+l-1);
		    				if (k<0) k = -(k+2);
		    				if (k == j) continue;
		    				long y = ((long)elPerGroup[j]) * ((sum[k] - sum[j]) - (((j>i && k > i) || ((j<i) && (k<i)))?0:elPerGroup[i]));
		    				res += x*y;
		    			}
		    		}
		    	}
		    	if (elPerGroup[i] > 2) {
		    		int l = len[i]*3;
		    		long x = ((elPerGroup[i]-2)*((long)(elPerGroup[i]-1))*(long)elPerGroup[i])/6;
		    		for (int j=0; j<ngroups; j++) {
		    			if (i != j && len[j] < l) {
		    				res += x*((long)elPerGroup[j]);
		    			}
		    		}
		    	}
		    	if (elPerGroup[i] > 3) {
		    		long x = (((long)(elPerGroup[i]-3))*(elPerGroup[i]-2)*((long)(elPerGroup[i]-1))*(long)elPerGroup[i])/24;
		    		res += x;
		    	}
		    }
		    
		    out.write(res+"\n");
		}
		
		out.close();
	}
}
